﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_TraCompany_psReName : System.Web.UI.Page
{
    // int CWProduct; 2007 1130 马 项目合并
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            // CWProduct = SysFun.ToInt(Request.QueryString["projectid"]);
            if ((Request.Form["xigai"] == "修改") && (Request.Form["chk"] != null))
            {
                string strSqlUp = "";
                strSqlUp += "@" + " update SupplyCompany set CompanyName_PS=CompanyName from Company where Company.AccountId=SupplyCompany.AccountId_PS and AccountId_PS in(" + Request.Form["chk"].ToString() + ") ";//and ProjectId =" + CWProduct;
                strSqlUp += "@" + " update SupplyPlan_Goods set CompanyName_SC=CompanyName from Company where Company.AccountId=SupplyPlan_Goods.AccountId_SC and AccountId_SC in(" + Request.Form["chk"].ToString() + ") ";//and ProjectId =" + CWProduct;
                strSqlUp += "@" + " update SupplyPlan_Goods set CompanyName_TB=CompanyName from Company where Company.AccountId=SupplyPlan_Goods.AccountId_TB and AccountId_TB in(" + Request.Form["chk"].ToString() + ") ";//and ProjectId =" + CWProduct;
                strSqlUp += "@" + " update SupplyPlan_Goods set CompanyName_PS=CompanyName from Company where Company.AccountId=SupplyPlan_Goods.AccountId_PS and AccountId_PS in(" + Request.Form["chk"].ToString() + ") ";// and ProjectId =" + CWProduct;
                strSqlUp += "@" + " update SupplyPlan_Goodsnext set companyname_ps_B1=CompanyName from Company where Company.AccountId=SupplyPlan_Goodsnext.Accountid_ps_B1 and Accountid_ps_B1 in(" + Request.Form["chk"].ToString() + ") ";// and ProjectId =" + CWProduct;
                strSqlUp += "@" + " update SupplyPlan_Goodsnext set companyname_ps_M=CompanyName from Company where Company.AccountId=SupplyPlan_Goodsnext.Accountid_ps_M and Accountid_ps_M in(" + Request.Form["chk"].ToString() + ") ";// and ProjectId =" + CWProduct;

                Db db = new Db();
                db.ExecuteTransaction(strSqlUp.Substring(1).Split(new char[] { '@' }), 30);
                db.Close();
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyCompany,SupplyPlan_Goods", strSqlUp, "../Agency/TraCompany_psReName.aspx");
                Response.Write("<script>alert('修改成功！');</script>");
            }
            databand();

        }
    }
    private void databand()
    {

        //Db db = new Db();
        // DbPage dbPage = new DbPage(db);
        // dbPage.Table = "SupplyPlan_Goods,Company";    //要查询的表明
        // dbPage.Key = "AccountId";        //表的主键 not null
        // dbPage.Where = madeSql();        //查询条件  
        // dbPage.SelectField = "distinct Company.AccountId,Company.companyname,Company.UserCode  ";
        // dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);  //要显示第几页 
        //// dbPage.PageSize = 15;        //没有显示记录条数 
        // dbPage.OrderBy = "CompanyName,AccountId";   //排序字段
        // System.Data.IDataReader dr = dbPage.ExecuteReader();
        // company_list.DataSource = dr;
        // company_list.DataBind();
        // dr.Close();
        // dr.Dispose();
        // dbPage.Db.Close();
        // db.Close();
        // this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

        string setrr = "select distinct Company.AccountId,Company.companyname,Company.UserCode from SupplyPlan_Goods,Company where " + madeSql();
        Db db = new Db();
        company_list.DataSource = db.DataTable(setrr);
        company_list.DataBind();
        db.Close();

    }
    private string madeSql() //生成查询语句
    {
        string strSql = "", _company_name, _UserCode_PS, _NameSame, _companysort;

        _company_name = Text_company_name.Text.ToString().Trim();
        _UserCode_PS = Text_usercode.Text.ToString().Trim();
        //_NameSame = DropDownList1.Text.Trim();
        //switch (_NameSame)
        //{

        //    case "不同":
        //        strSql = " ((CompanyName<>CompanyName_PS and Company.AccountId=SupplyPlan_Goods.Accountid_ps) or (CompanyName<>CompanyName_tb and Company.AccountId=SupplyPlan_Goods.Accountid_tb) or (CompanyName<>CompanyName_sc or Company.AccountId=SupplyPlan_Goods.Accountid_sc)) ";
        //        break;

        //}
        _companysort = DropDownList2.Text.Trim();
        switch (_companysort)
        {
            case "生产企业":
                strSql = "(CompanyName<>CompanyName_sc and Company.AccountId=SupplyPlan_Goods.Accountid_sc) ";
                break;
            case "投标企业":
                strSql = "(CompanyName<>CompanyName_tb and Company.AccountId=SupplyPlan_Goods.Accountid_tb) ";
                break;
            case "配送企业":
                strSql = "(CompanyName<>CompanyName_PS and Company.AccountId=SupplyPlan_Goods.Accountid_ps) ";
                break;

        }
        if (_company_name != "")
        {
            strSql = strSql + " and  CompanyName like '%" + _company_name + "%'";
        }

        if (_UserCode_PS != "")
        {
            strSql = strSql + " and UserCode = '" + _UserCode_PS + "'";
        }
        return strSql;
    }
    #region TraDes 成员

    public string Name
    {
        get { return "企业管理"; }
    }

    public string Describe
    {
        get { return "企业管理"; }
    }

    public string ParentName
    {
        get { return "企业管理"; }
    }


    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            return _AccountType;
        }
    }
    #endregion
}
